package com.woniuxy.cloud.depositassembly.controller;

import com.woniuxy.cloud.api.dto.DepositOrderDto;
import com.woniuxy.cloud.api.param.BackDepositParam;
import com.woniuxy.cloud.demo.Result;
import com.woniuxy.cloud.depositassembly.param.OrderParam;
import com.woniuxy.cloud.depositassembly.service.DepositOrderService;
import com.woniuxy.cloud.depositassembly.util.ValidateUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.BindingResult;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * @author 高强  2022/2/25
 */
@RestController
@Slf4j
public class DepositController {

    @Resource
    private DepositOrderService orderService;

    /**
     * 生成充值订单
     *生成充值押金账单，支付时间5分钟，测试时间1分钟
     * @param
     * @return
     */
    @PostMapping("/addDepositOrder")
    public Result<DepositOrderDto> addDepositOrder(@RequestBody @Validated OrderParam orderParam, BindingResult result){
        //参数验证
        ValidateUtil.ValidatedException(result);
        DepositOrderDto dto = orderService.AddDepositOrder(orderParam);
        return Result.newInstance().setCode(200).setMsg("下单成功").setData(dto);
    }

    /**
     * 退押金
     */
    @PutMapping("/depositRefund")
    public Result<String> depositRefund(@RequestBody @Validated BackDepositParam param,BindingResult result){
        ValidateUtil.ValidatedException(result);
        return Result.newInstance().setCode(200).setMsg("退款成功").setData(orderService.depositRefund(param));
    }


}
